/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ClassesJava;

import connexion.ConnectionManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author ISMAYLOULABBIHI
 */
public class Cour {

    public ConnectionManager c;
    private String description;

    private int numMatier;
    private int numsalle;
    private int idFiliere;
    private int idProf;
    private int col;
    private int row;

    public Cour(int idFiliere, int numMatier, int idProf , int numsalle, int row, int col) {
        this.numMatier = numMatier;
        this.numsalle = numsalle;
        this.idFiliere = idFiliere;
        this.idProf = idProf;
        this.col = col;
        this.row = row;
    }

    public Cour(int f, int r, int c) {
        description = null;
        idFiliere = f;
        col = c;
        row = r;
    }

    public Cour() {
    }

    public int getCol() {
        return col;
    }

    public void setCol(int col) {
        this.col = col;
    }

    public int getRow() {
        return row;
    }

    public void setRow(int row) {
        this.row = row;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public int getNumMatier() {
        return numMatier;
    }

    public void setNumMatier(int numMatier) {
        this.numMatier = numMatier;
    }

    public int getNumsalle() {
        return numsalle;
    }

    public void setNumsalle(int numsalle) {
        this.numsalle = numsalle;
    }

    public int getIdFiliere() {
        return idFiliere;
    }

    public void setIdFiliere(int idFiliere) {
        this.idFiliere = idFiliere;
    }

    public int getIdProf() {
        return idProf;
    }

    public void setIdProf(int idProf) {
        this.idProf = idProf;
    }

    public int ajoutersCour(Cour r) {
        int i;
        c = new ConnectionManager();
        String rq = "INSERT INTO  `gestion_des_emplois`.`cours` ( id_f,row,col)"
                + " VALUES ('" + r.getIdFiliere() + "', " + r.getRow() + "," + r.getCol() + ")";
        i = c.setDataBase(rq);
        return i;
    }

    public int updateCour(Cour r) {
        int i;
        c = new ConnectionManager();
        String rq = "UPDATE  cours SET  `id_m` = '" + r.getNumMatier() + "', `id_p` = '" + r.getIdProf() + "',"
                + "`id_s` = '" + r.getNumsalle() + "' WHERE  id_f =" + r.getIdFiliere() + " and row = " + r.getRow()
                + " and col = " + r.getCol();
        i = c.setDataBase(rq);
        return i;
    }

    public Vector<Cour> getCourByFiliere(Filiere f) {
        Vector<Cour> res = new Vector();
        try {
            c = new ConnectionManager();
            ResultSet rs = c.getDataBase("SELECT * FROM cours WHERE id_f =" + f.getNum());

            while (rs.next()) {
                Cour c = new Cour(rs.getInt(2), rs.getInt(3), rs.getInt(4), rs.getInt(5), rs.getInt(6),rs.getInt(6));
                res.add(c);
            }

        } catch (SQLException ex) {
            Logger.getLogger(Salle.class.getName()).log(Level.SEVERE, null, ex);
        }

        return res;
    }
}
